import logging

import config


class RechargeApi:

    def __init__(self, session):
        # 接收session对象的变量
        self.session = session

    # 获取充值验证码接口
    def get_recharge_verify_code(self, r):
        url = config.BASE_HOST + "/common/public/verifycode/{}".format(r)
        res = self.session.get(url=url)
        logging.info("获取充值验证码接口返回的响应状态码：{}".format(res.status_code))
        return res

    # 充值接口
    def recharge(self, amount, vailcode, paymentType="chinapnrTrust", formStr="reForm"):
        url = config.BASE_HOST + "/trust/trust/recharge"
        # 定义一个字典变量，用来接收请求体数据
        form_dict = {"paymentType": paymentType, "amount": amount, "formStr": formStr, "valicode": vailcode}
        res = self.session.post(url=url, data=form_dict)
        logging.info("充值接口返回的响应体数据：{}".format(res.json()))
        return res

    # 第三方充值接口
    def third_recharge(self, url, form_dict):
        res = self.session.post(url=url, data=form_dict)
        logging.info("充值接口返回的响应体数据：{}".format(res.text))
        return res
